<template>
  <div class="wholeView">
    <el-table :header-cell-style="headerClass" :span-method="objectMethod" :data="tableData" v-loading="tableLoading" style="width: 100%" border>
      <el-table-column prop="class1" align="center" label="收入环比趋势(万元)">
        <el-table-column prop="class1" align="center" label="收入环比趋势(万元)"></el-table-column>
        <el-table-column prop="class2" align="center" label="收入环比趋势(万元)"></el-table-column>
        <el-table-column prop="vertical_index_name" align="center" label="收入环比趋势(万元)"></el-table-column>
      </el-table-column>
      <el-table-column :prop="item" align="center" :label="item" v-for="(item,index) in headerList" :key="index"></el-table-column>
    </el-table>
  </div>
</template>

<script>
// import { stepsSubject } from "@/api/barCode/index";

import $barCodeApi from "@/api/barCode/index";

export default {
  name: "wholeView",
  components: {},
  props: {
    form: {
      type: Object,
      default: {},
    },
  },
  watch: {
    form: {
      handler () {
        this.getData();
      },
      deep: true,
    },
  },
  data () {
    return {
      tableLoading: false,
      tableData: [],
      spanArr1: [],
      spanArr2: [],
      headerList: []
    };
  },
  computed: {

  },
  created () { },
  mounted () { },
  methods: {
    getData () {
      this.tableData = []
      this.tableLoading = true;





      $barCodeApi.stepsSubject({ ...this.form }, res => {
        if (res.code == 0) {
          this.tableLoading = false;
          this.headerList = res.data.area
          this.tableData = res.data.data;
          let contactDot = 0;
          let spanArr1 = [];
          let contactDot1 = 0;
          let spanArr2 = [];
          this.tableData.forEach((item, index) => {
            if (index === 0) {
              spanArr1.push(1);
              spanArr2.push(1);
            } else {
              if (item.class1 === this.tableData[index - 1].class1) {
                spanArr1[contactDot] += 1;
                spanArr1.push(0);
              } else {
                contactDot = index;
                spanArr1.push(1);
              }
              if (item.class2 === this.tableData[index - 1].class2) {
                spanArr2[contactDot1] += 1;
                spanArr2.push(0);
              } else {
                contactDot1 = index;
                spanArr2.push(1);
              }
            }
          });
          this.spanArr1 = spanArr1;
          this.spanArr2 = spanArr2;
        }
      });






      // stepsSubject(this.form).then((res) => {
      //   if (res.code == 0) {
      //     this.tableLoading = false;
      //     this.headerList = res.data.area
      //     this.tableData = res.data.data;
      //     let contactDot = 0;
      //     let spanArr1 = [];
      //     let contactDot1 = 0;
      //     let spanArr2 = [];
      //     this.tableData.forEach((item, index) => {
      //       if (index === 0) {
      //         spanArr1.push(1);
      //         spanArr2.push(1);
      //       } else {
      //         if (item.class1 === this.tableData[index - 1].class1) {
      //           spanArr1[contactDot] += 1;
      //           spanArr1.push(0);
      //         } else {
      //           contactDot = index;
      //           spanArr1.push(1);
      //         }
      //         if (item.class2 === this.tableData[index - 1].class2) {
      //           spanArr2[contactDot1] += 1;
      //           spanArr2.push(0);
      //         } else {
      //           contactDot1 = index;
      //           spanArr2.push(1);
      //         }
      //       }
      //     });
      //     this.spanArr1 = spanArr1;
      //     this.spanArr2 = spanArr2;
      //   }
      // });
    },
    objectMethod ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (this.spanArr1[rowIndex]) {
          return {
            rowspan: this.spanArr1[rowIndex],
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
      if (columnIndex === 1) {
        if (this.spanArr2[rowIndex]) {
          return {
            rowspan: this.spanArr2[rowIndex],
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
    headerClass ({ rowIndex }) {
      if (rowIndex === 1) {
        return { display: 'none' }
      }
      return 'background:#0070C0;color:#FFFF'
    }
  },
};
</script>

<style scoped>
</style>
